package com.lzm.back.controller;

import com.github.pagehelper.PageInfo;
import com.lzm.back.common.MyResult;
import com.lzm.back.entity.Registration;
import com.lzm.back.entity.Status;
import com.lzm.back.service.RegistrationService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


//报名    情况

@RestController
@RequestMapping("Registration")
public class RegistrationController {

    @Resource
    private RegistrationService service;


    @GetMapping("/SelectRegistrationInformation")
    public MyResult SelectRegistrationInformation(Registration registration,
                                                  @RequestParam(required = false) String username,//参赛者姓名
                                                  @RequestParam(required = false) String name,//赛事类别名
                                                  @RequestParam(required = false) Status status,//赛事状态
                                                  @RequestParam(required = false) LocalDateTime applyTime,//赛事时间
                                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                                  @RequestParam(defaultValue = "5") Integer pageSize) {


        PageInfo<Registration> registrationPageInfo = service.selectPage(registration, username, name, status, applyTime, pageNum, pageSize);

        return MyResult.success(registrationPageInfo);
    }

    //报名
    @PostMapping("/addRegistrationInformation")
    public MyResult addRegistrationInformation(@RequestBody Registration registration) {
        service.addRegistrationInformation(registration);
        return MyResult.success();
    }

    //报名审核
    @PutMapping("/updateRegistrationInformation")
    public MyResult updateRegistrationInformation(@RequestBody Registration registration) {
        service.updateRegistrationInformation(registration);
        return MyResult.success();
    }

    //删除一个报名信息
    @DeleteMapping("/{id}")
    public MyResult delRegistrationInformation(@PathVariable Long id) {
        service.delRegistrationInformation(id);
        return MyResult.success();
    }
    //批量删除
    @DeleteMapping("/batch")
    public MyResult delRegistrationInformationBaTch(@RequestBody List<Long> ids) {
        service.delRegistrationInformationBaTch(ids);
        return MyResult.success();
    }
}
